import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * Creat with IntelliJ IDEA
 * Description
 * User: mamba24
 * Date: 2022-07-17
 * Time: 10:33
 * To BE A Better Person-2020-3-2
 */
public class JDBCselect {
    public static void main(String[] args) throws SQLException {
        //1.创建数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource) dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/bitcompany?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource) dataSource).setUser("root");
        ((MysqlDataSource) dataSource).setPassword("lakers26");
        Connection connection = dataSource.getConnection();

        Scanner sc = new Scanner(System.in);
        //11条记录
        //hhh
        int i=7;
        String sql = "insert into salary values (?,?,?,?)";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        while (i>0) {
            int salary_id = sc.nextInt();
            int staff_id = sc.nextInt();
            int salary= sc.nextInt();
            int month= sc.nextInt();
            preparedStatement.setInt(1, salary_id);
            preparedStatement.setInt(2, staff_id);
            preparedStatement.setInt(3, salary);
            preparedStatement.setInt(4, month);
            preparedStatement.executeUpdate();
            i--;
       }

        preparedStatement.close();
        connection.close();
    }
}
